require 'apr.std.table'
require 'moonunit'

test_std = moonunit.TestCase:new()

function test_std:test_tablekeys()
    local test = {a = 'b', c = 'd'}
    local keys = apr.std.table.keys(test)
    local first = keys[1]
    local second = keys[2]
    
    assert(first == 'a' or second == 'c')
    assert(second == 'a' or second == 'c')
    assert(#keys == 2)
    
    for key in apr.std.table.iterkeys(test) do
        assert(key == 'a' or key == 'c')
    end
end

function test_std:test_caselesstable()
    local test = apr.std.table.caselesstable{a=1}
    assert(test.A == 1)
    assert(test.a == 1)
    assert(test.b == nil)
    
    test[5] = 'fifth'
    
    test['B5'] = 2
    assert(test['b5'] == 2)
    
    test['b5'] = 5
    assert(test['B5'] == 5)
    
    assert(test[5] == 'fifth')
end

function test_std:test_defaulttable()
    local testval = apr.std.table.defaulttable(3, {b=2})
    assert(testval['b'] == 2)
    testval['a'] = testval['a'] + 1
    assert(testval['a'] == 4)
end
